[READ-ONLY] Mirror of https://github.com/flo-bit/skywatched. review movies and tv shows, based on at proto
skywatched.app
1// src/routes/og/+server.ts
2import { getDetails } from '$lib/server/movies';
3import { ImageResponse } from '@ethercorps/sveltekit-og';
4import { error, type RequestHandler } from '@sveltejs/kit';
5
6const template = (data: {
7 backdrop_path: string;
8 poster_path: string;
9 title?: string;
10 name?: string;
11}) => {
12 return `
13<div tw="bg-zinc-900 flex flex-col w-full h-full items-center justify-center">
14
15 <div tw="flex absolute bottom-0 left-0 right-0 top-0 bg-sky-400">
16 <img src="https://image.tmdb.org/t/p/w780${data.backdrop_path}" alt="" class="flex h-full w-full rounded-xl opacity-50" />
17
18 <div tw="flex absolute h-full w-full bg-black/80">
19 </div>
20 </div>
21
22 <div tw="flex flex-row w-full py-8 px-16 items-center justify-start">
23 <div tw="flex h-auto aspect-[3/2] w-72">
24 <img src="https://image.tmdb.org/t/p/w500${data.poster_path}" alt=""
25 class="flex h-full w-full rounded-xl border-2 border-zinc-800" style="border-radius: 16px; border-width: 1px; border-color: #3f3f46;" />
26 </div>
27
28 <h2 tw="flex flex-col text-7xl font-bold text-zinc-100 text-left px-12 max-w-3xl">
29 <span tw="flex tracking-tight">${data.title ?? data.name}</span>
30 </h2>
31 </div>
32
33 <div tw="flex text-4xl text-sky-400 items-end justify-end w-full px-8">
34 <div tw="flex">
35 rate on skywatched.app
36 </div>
37 </div>
38</div>`;
39};
40
41const host = import.meta.env.DEV ? 'http://localhost:5173' : 'https://skywatched.app';
42const fontPath = `fonts/inter-latin-ext-400-normal.woff`;
43const fontFile = await fetch(`${host}/${fontPath}`);
44const fontData: ArrayBuffer = await fontFile.arrayBuffer();
45
46export const GET: RequestHandler = async ({ params }) => {
47 const id = parseInt(params.id?.split('-')[0] ?? '');
48 const kind = params.kind;
49
50 if (kind !== 'movie' && kind !== 'tv') {
51 return error(404, 'Not found');
52 }
53
54 if (!id) {
55 return error(404, 'Not found');
56 }
57 const result = await getDetails(id, kind);
58
59 return new ImageResponse(
60 template(result),
61 {
62 fonts: [
63 {
64 name: 'Inter Latin',
65 data: fontData,
66 weight: 400
67 }
68 ]
69 },
70 {}
71 );
72};